<?
	global $kam_admin, $FullUrl, $arr, $table_edit, $element, $config_xml_list;
    $edit_url = 'admin-pro.html?do='.$table_edit.'&act=edit_full&id=';
    $delete_url = 'admin-pro.html?do='.$table_edit.'&act=del&id=';
    $deletelist_url = 'admin-pro.html?do='.$table_edit.'&act=dellist';
    $showlist_url = 'admin-pro.html?do='.$table_edit.'&act=show';
    $hidelist_url = 'admin-pro.html?do='.$table_edit.'&act=hide';
    $changeactive_url='admin-pro.html?do='.$table_edit.'&&act=changeactive&page='.(isset($_GET['page'])?$_GET['page']:'1').'&id=';
    $changeorder_url = 'admin-pro.html?do='.$table_edit.'&act=order';
?>
<!-- Alternative Content Box Start -->
<?
	//print_r($arr);
    //echo $config_xml_list[30];
?>

<div class="contentcontainer">
  <div class="headings altheading">
    <h2>Categories</h2>
  </div>
  <form name="f" id="f" method="post">
    <div class="contentbox">
      <table width="100%">
        <thead>
          <tr>
            <th>ID</th>
            <th><input type="submit" value="Change Order" class="btn" onclick="ChangeAction('<?=$changeorder_url?>');return false;"/></th>
            <th>Name</th>
            <th>Component</th>
            <th>Show</th>
            <th>Edit</th>
            <th>Delete</th>
            <th><input name="" type="checkbox" value="" onclick="checkAll();return false;" id="all"/></th>
          </tr>
        </thead>
        <tbody>
          <? 
                if($c>0 && $element!=null) {
                for ($i=0;$i<count($element);$i++) 
                {
                	$element_id = $element[$i]['id'];
                	$element_num = $element[$i]['num'];
                    $element_name = $element[$i]['name_vn'];
                    $element_show = $kam_admin.'/images/icons/icon_'.(($element[$i]['showed']=='0')?'un':'').'approve.png';
                                                    
                                                    ?>
          <tr <?=($i%2) == 0 ? 'class="alt"' : ''?>>
            <td><?=$element_id?></td>
            <td><input type="text" id="smallbox" class="inputbox smallbox2" value="<?=$element_num?>" name="ordering[]" onkeypress="return OnlyNumber(event)"/>
              <input type="hidden" name="id[]" value="<?=$element_id?>" /></td>
            <td style="color:#00F;"><?php
            if($element[$i]["has_child"] == '1'){
                print('<a href="admin-pro.html?do=categories&cid='.$element[$i]["id"].'&root='.$_GET['root'].'" border="0" >');
            }														
            ?>
              <?=$element_name?>
              <?php
            if($element[$i]["has_child"] == '1'){
                print('</a>');
            }														
            ?></td>
            <td><?php
                if($element[$i]["has_child"] == '0'){
                    global $db;
                    $sql = "select * from component where id=".$element[$i]["comp"];
                    $r = $db->getRow($sql);
                ?>
              <a href="admin-pro.html<?php echo $r['back_link']; ?>&cid=<?php echo $element[$i]["id"]; ?>"><?php echo $r["name"]; ?></a>
              <?php
                }
                ?></td>
            <td><a href="<?=$changeactive_url.$element_id?>&current=<?=$element[$i]['active']?>" title=""><img src="<?=$element_show?>" alt="Approve/Unapprove" title="Click vào để thay đổi"/></a></td>
            <td><a href="<?=$edit_url.$element_id?>" title=""><img src="<?=$kam_admin?>/images/icons/icon_edit.png" alt="Edit" title="Click vào đây để chỉnh sửa"/></a></td>
            <td><a href="<?=$delete_url.$element_id?>" title=""><img src="<?=$kam_admin?>/images/icons/icon_delete.png" alt="Delete" title="Click vào đây để xóa"/></a></td>
            <td><input type="checkbox" value="<?=$element_id?>" name="iddel[]" id="check<?=$i?>"/></td>
          </tr>
          <?  }}else{ ?>
          <tr>
            <td>No Data</td>
          </tr>
          <?}?>
        </tbody>
      </table>
      <div class="extrabottom">
        <div class="bulkactions">
          <ul>
            <li><a onclick="ChangeAction('<?=$showlist_url?>');return false;" href=""><img src="<?=$kam_admin?>/images/icons/icon_approve.png" alt="Approve" /> Show</a></li>
            <li><a onclick="ChangeAction('<?=$hidelist_url?>');return false;" href=""><img src="<?=$kam_admin?>/images/icons/icon_unapprove.png" alt="Unapprove" /> Hide</a></li>
            <li><a onclick="ChangeAction('<?=$deletelist_url?>');return false;" href=""><img src="<?=$kam_admin?>/images/icons/icon_delete.png" alt="Delete" /> Remove</a></li>
          </ul>
        </div>
      </div>
      <?=$plpage?>
      <div style="clear: both;"></div>
    </div>
  </form>
</div>
<script>
function ChangeAction(str){
	if(confirm("Are You Sure?"))
	{
		document.f.action = str;
		document.f.submit();
	}
}
function checkAll()
{
	if(document.f.all.checked == true)
	{
		for(var i=0;i<20;i++)
		{
			
			document.getElementById("check"+i).checked = true;
		}
	}
	else
	{
		for(var i=0;i<20;i++)
		{
			
			document.getElementById("check"+i).checked = false;
		}
	}
	
}
function tran()
{
	location.href="admin-pro.html?do=page&act=add";
}
function TreeFilterChanged(value){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  } 
	var url="ajax/check.php";
	url=url+"?id="+value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=ReadyTreeFilterChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}
function ReadyTreeFilterChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 	
		if(xmlHttp.responseText != "0")
			location.href = "admin-pro.html?do=categories&act=list&cid="+xmlHttp.responseText+"&root=1";
		else{
			alert('Thể loại này không thể có mục con');
		}
	}
}

</script> 
